/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aptech.builder;

import aptech.container.Constants;
import aptech.entities.Activity;
import aptech.entities.TypeOfActivity;
import aptech.entities.Users;
import java.util.List;

/**
 *
 * @author home
 */
public class XmlBuilder {

    public static String getXMLActivity(Activity activity) throws Exception {
        if (activity != null) {
            StringBuilder xml = new StringBuilder();
            xml.append("<activity>");
                xml.append("<" + Constants.ACTIVITY_ID + ">");
                    xml.append(activity.getActivityId());
                xml.append("</" + Constants.ACTIVITY_ID + ">");
                xml.append("<" + Constants.TYPE_ACTIVITY_ID + ">");
                    xml.append(activity.getTypeOfActivity().getTypeActivityId());
                xml.append("</" + Constants.TYPE_ACTIVITY_ID + ">");
                xml.append("<" + Constants.TYPE_ACTIVITY_NAME + ">");
                    xml.append(activity.getTypeOfActivity().getTypeActivityName());
                xml.append("</" + Constants.TYPE_ACTIVITY_NAME + ">");
                xml.append("<" + Constants.ACTIVITY_TITLE + ">");
                    xml.append(activity.getTitleActivity());
                xml.append("</" + Constants.ACTIVITY_TITLE + ">");
                xml.append("<" + Constants.ACTIVITY_DATE + ">");
                    xml.append(activity.getDateOfActivity());
                xml.append("</" + Constants.ACTIVITY_DATE + ">");
                xml.append("<" + Constants.ACTIVITY_TIME_DURATION + ">");
                    xml.append(activity.getTimeDuaration());
                xml.append("</" + Constants.ACTIVITY_TIME_DURATION + ">");
                xml.append("<" + Constants.ACTIVITY_LOCATION + ">");
                    xml.append(activity.getLocaltion());
                xml.append("</" + Constants.ACTIVITY_LOCATION + ">");
                xml.append("<" + Constants.ACTIVITY_FEE + ">");
                    xml.append(activity.getFee());
                xml.append("</" + Constants.ACTIVITY_FEE + ">");
                xml.append("<" + Constants.ACTIVITY_CURRENT_PEOPLE + ">");
                    xml.append(activity.getCurrentPeople());
                xml.append("</" + Constants.ACTIVITY_CURRENT_PEOPLE + ">");
                xml.append("<" + Constants.ACTIVITY_LIMITTED_PEOPLE + ">");
                    xml.append(activity.getLimittedPeople());
                xml.append("</" + Constants.ACTIVITY_LIMITTED_PEOPLE + ">");
                xml.append("<" + Constants.ACTIVITY_EMAIL_ORGANIZER + ">");
                    xml.append(activity.getEmailOfOrganizer());
                xml.append("</" + Constants.ACTIVITY_EMAIL_ORGANIZER + ">");
                xml.append("<" + Constants.ACTIVITY_DESCRIPTION + ">");
                    xml.append(activity.getDescription());
                xml.append("</" + Constants.ACTIVITY_DESCRIPTION + ">");
                xml.append("<" + Constants.ACTIVITY_STATUS + ">");
                    xml.append(activity.getStatusOfActivity());
                xml.append("</" + Constants.ACTIVITY_STATUS + ">");
            xml.append("</activity>");
            return xml.toString();
        }
        return null;
    }

    public static String getListActivitiesBySchedule(List<Activity> list) throws Exception{
        if(list!=null){
            StringBuilder xml = new StringBuilder();
            xml.append("<result>");
            if(list.size() == 0){
                xml.append("null");
            }else{
                for (int i= 0; i < list.size(); i++) {
                xml.append(getXMLActivity(list.get(i)));
            }
            }
            
            
            xml.append("</result>");
            return xml.toString();
        }
        return null;
    }

    //use for autoload
    public static String getXMLActivity_Mini(Activity activity) throws Exception{
        if (activity != null) {
            StringBuilder xml = new StringBuilder();
            xml.append("<activity>");
                xml.append("<" + Constants.ACTIVITY_ID + ">");
                    xml.append(activity.getActivityId());
                xml.append("</" + Constants.ACTIVITY_ID + ">");
                xml.append("<" + Constants.ACTIVITY_CURRENT_PEOPLE + ">");
                    xml.append(activity.getCurrentPeople());
                xml.append("</" + Constants.ACTIVITY_CURRENT_PEOPLE + ">");
                xml.append("<" + Constants.ACTIVITY_LIMITTED_PEOPLE + ">");
                    xml.append(activity.getLimittedPeople());
                xml.append("</" + Constants.ACTIVITY_LIMITTED_PEOPLE + ">");
                xml.append("<" + Constants.ACTIVITY_STATUS + ">");
                    xml.append(activity.getStatusOfActivity());//True / False
                xml.append("</" + Constants.ACTIVITY_STATUS + ">");
            xml.append("</activity>");
            return xml.toString();
        }
        return null;
    }

    //auto load
    public static String getListActivity_Mini(List<Activity> list) throws Exception{
       if(list!=null){
            StringBuilder xml = new StringBuilder();
            xml.append("<result>");
            if(list.size() == 0){
                xml.append("null");
            }else{
                for (int i= 0; i < list.size(); i++) {
                    xml.append(getXMLActivity_Mini(list.get(i)));
                }
            }
            xml.append("</result>");
            return xml.toString();
        }
        return null;
    }

    public static String getXMLUser(Users user) throws Exception{
        if(user!=null){
            StringBuilder xml = new StringBuilder();
            //xml.append("<result>");
                xml.append("<user>");
                    xml.append("<" + Constants.USER_ID + ">");
                        xml.append(user.getUserId());
                    xml.append("</" + Constants.USER_ID + ">");
                    xml.append("<" + Constants.TYPE_USER_NAME + ">");
                        xml.append(user.getTypeOfUser().getTypeUserName());
                    xml.append("</" + Constants.TYPE_USER_NAME + ">");
                    xml.append("<" + Constants.USER_NAME + ">");
                        xml.append(user.getUsernameLogin());
                    xml.append("</" + Constants.USER_NAME + ">");
                    xml.append("<" + Constants.EMAIL + ">");
                        xml.append(user.getEmailLogin());
                    xml.append("</" + Constants.EMAIL + ">");
                    xml.append("<" + Constants.STATUS_ACTIVE + ">");
                        xml.append(user.getStatusActive());
                    xml.append("</" + Constants.STATUS_ACTIVE + ">");
                xml.append("</user>");
            //xml.append("</result>");
            return xml.toString();
        }
        return null;
    }

    public static String getXMLTypeOfActivity(TypeOfActivity typeofactivity){

        if (typeofactivity != null) {
            StringBuilder xml = new StringBuilder();
            xml.append("<typeofactivity>");
                xml.append("<" + Constants.TYPE_ACTIVITY_ID + ">");
                    xml.append(typeofactivity.getTypeActivityId());
                xml.append("</" + Constants.TYPE_ACTIVITY_ID + ">");
                xml.append("<" + Constants.TYPE_ACTIVITY_NAME + ">");
                    xml.append(typeofactivity.getTypeActivityName());
                xml.append("</" + Constants.TYPE_ACTIVITY_NAME + ">");
            xml.append("</typeofactivity>");
            return xml.toString();
        }
        return null;
    }

    public static String getListTypeOfActivity(List<TypeOfActivity> list){
        if(list!=null){
            StringBuilder xml = new StringBuilder();
            xml.append("<result>");
            for (int i= 0; i < list.size(); i++) {
                xml.append(getXMLTypeOfActivity(list.get(i)));
            }
            xml.append("</result>");
            return xml.toString();
        }
        return null;

    }
}
